﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace PJ.Data
{
    public class ItemProviderClient<S, D> : EntityProviderClient<S, D>, IItemProvider<D>
        where D : BaseItemData, new()
        where S : class, IItemProvider<D>
    {
        public ItemProviderClient() {
        }
        
        public ItemProviderClient(string endpointConfigurationName) : 
                base(endpointConfigurationName) {
        }
        
        public ItemProviderClient(string endpointConfigurationName, string remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }
        
        public ItemProviderClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }

        public ItemProviderClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(binding, remoteAddress) {
        }

        public D GetByName(string name)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException();
            return base.Channel.GetByName(name);
        }
        public D FindByName(string name)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException();
            return base.Channel.FindByName(name);
        }

        public D CachedGetByName(string name)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException();
            return base.Channel.CachedGetByName(name);
        }
        public D CachedFindByName(string name)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException();
            return base.Channel.CachedFindByName(name);
        }
        public IEnumerable<string> Search(string searchTxt)
        {
            if (string.IsNullOrEmpty(searchTxt))
                throw new ArgumentNullException();
            return base.Channel.Search(searchTxt);
        }
        public IEnumerable<string> CachedSearch(string searchTxt)
        {
            if (string.IsNullOrEmpty(searchTxt))
                throw new ArgumentNullException();
            return base.Channel.CachedSearch(searchTxt);
        }

        #region Interface override
        IItemData IItemProvider.GetByName(string name)
        {
            return GetByName(name);
        }

        IItemData IItemProvider.CachedGetByName(string name)
        {
            return CachedGetByName(name);
        }

        IItemData IItemProvider.FindByName(string name)
        {
            return GetByName(name);
        }

        IItemData IItemProvider.CachedFindByName(string name)
        {
            return GetByName(name);
        }
        #endregion


    }
}
